/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edmo.fastener.slave;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author obelog
 */
public class GenerateCustomer {
    private ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
    private IocBean dir = (IocBean) context.getBean("folder");
    
    public static void main(String[] args){
        new GenerateCustomer().writeData();
    }

    public void writeData() {
        try {
            IocBean ioc = (IocBean) context.getBean("customer");
            File file = new File(ioc.getName());
            new File(dir.getName()+"\\CUSTOMERS").mkdirs();

            if (!file.exists()) {
                file.createNewFile();
            }

            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            generator(bw);
            bw.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    private void generator(BufferedWriter bw) throws IOException{
        for (int i=1; i<501; i++){
            new File(dir.getName()+"\\CUSTOMERS\\" + "C" + i).mkdirs();
            String content = "C" + i + "|State" + (int)(Math.random() * 51 + 1) +"\n";
            bw.write(content);
        }
    }
}
